<!DOCTYPE html>
<html>
    <head>
        <title>Attr empty value tests</title>
        <script>
            if (window.testRunner) {
                testRunner.dumpAsText();
            }
            function isReallyEmpty(attr) {
                return attr.value === ""
                && attr.hasChildNodes() === false
                && attr.firstChild === null
                && attr.lastChild === null
                && attr.childNodes.length === 0;
            }
            window.onload = function() {
                var tests = [];
                var dynamicAttr = document.createAttribute("foo");
                tests[0] = isReallyEmpty(dynamicAttr);

                dynamicAttr.value = "";
                tests[1] = isReallyEmpty(dynamicAttr);

                dynamicAttr.value = "bar";
                dynamicAttr.value = "";
                tests[2] = isReallyEmpty(dynamicAttr);

                var parsedAttr = document.body.getAttributeNode("id");
                tests[3] = isReallyEmpty(parsedAttr);

                parsedAttr.value = "";
                tests[4] = isReallyEmpty(parsedAttr);

                parsedAttr.value = "bar";
                parsedAttr.value = "";
                tests[5] = isReallyEmpty(parsedAttr);

                var parsedAttrIntitiallyNonEmpty = document.body.getAttributeNode("class");
                parsedAttrIntitiallyNonEmpty.value = "";
                tests[6] = isReallyEmpty(parsedAttrIntitiallyNonEmpty);

                parsedAttrIntitiallyNonEmpty.value = "bar";
                parsedAttrIntitiallyNonEmpty.value = "";
                tests[7] = isReallyEmpty(parsedAttrIntitiallyNonEmpty);

                document.body.setAttribute("title", "");

                var parsedAttrNodeChangedToEmptyBySetAttribute = document.body.getAttributeNode("title");
                tests[8] = isReallyEmpty(parsedAttrNodeChangedToEmptyBySetAttribute);

                parsedAttrNodeChangedToEmptyBySetAttribute.value = "bar";
                parsedAttrNodeChangedToEmptyBySetAttribute.value = "";
                tests[9] = isReallyEmpty(parsedAttrNodeChangedToEmptyBySetAttribute);

                var results = document.getElementsByTagName("p")[1];
                while (results.hasChildNodes()) {
                    results.removeChild(results.lastChild);
                }

                for (var i = 0; i < tests.length; ++i) {
                    var pass = tests[i] ? "PASS" : "FAIL";
                    results.appendChild(document.createTextNode("SubTest " + (i + 1) + " = " + pass));
                    results.appendChild(document.createElement("br"));
                }

                var completely = "PASS";
                for (var i = 0; i < tests.length; ++i) {
                    if (tests[i] === false) {
                        completely = "FAIL";
                        break;
                    }
                }
                results.appendChild(document.createTextNode("Complete Test = " + completely));
            };
        </script>
    </head>
    <body id="" class="test" title="test">
        <h1>Attr empty value tests <a href="https://bugs.webkit.org/show_bug.cgi?id=16923">Bug 16923</a></h1>
        <p>In Opera, Firefox and IE, when an Attr's value is an empty string, the Attr node won't have any childNodes. The following 12 tests will see if this is true for WebKit for both parsed and dynamically-created Attr nodes. The tests use multiple methods of changing the Attr's value and even test reverting from a non-empty value to an empty one to check that all childNodes were removed. Some of the tests make use of .textContent, so this test is not compatible with IE. Opera and Firefox both completely pass this test.</p>
        <p>This test requires Javascript.</p>
    </body>
</html>
